#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

int n;
int a[N];

void solve(){
	for(int i = 0;i < n;i ++){
		cin >> a[i];
	}
	int ans = 0;
	for(int i = 0;i < (1 << n);i ++){
		int sum = 0, last0 = -1, last1 = -1;
		for(int j = 0;j < n;j ++){
			if(i & (1 << j)){
				if(last1 != -1){
					if(a[j] == a[last1]) sum += a[j];
				}
				last1 = j;
			} else {
				if(last0 != -1){
					if(a[j] == a[last0]) sum += a[j];
				}
				last0 = j;
			}
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

int t[1000000 + 10];

void work(){
	cin >> n;
	if(n <= 15){
		solve();
		return ;
	}
	bool f = true;
	for(int i = 1;i <= n;i ++){
		cin >> a[i];
		if(a[i] > 10) f = false;
		t[a[i]] ++;
	}
	int ans = 0;
	for(int i = 1;i <= n;i ++){
		ans += a[i] * (t[a[i]] - 1);
	}
	cout << ans << endl;
	
}

int main(){
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	int T; cin >> T;
	while(T --) work();
	return 0;
}
